package Receive;

import java.io.IOException;
import java.io.Serializable;

public class SNS extends Receive_Packet implements Serializable {

	public float avg_grade;
	public Opinion[] op;

	public SNS(byte[] packet) {
		super(packet);
	}

	public void get_grade(byte[] packet) {
		byte[] temp = new byte[4];
		System.arraycopy(packet, 5, temp, 0, 4);
		this.avg_grade = byteTofloat(temp);
	}

	public void get_Opinion(byte[] packet) throws IOException {
		int temp_length = packet.length - 9;
		byte[] temp = new byte[temp_length];
		System.arraycopy(packet, 9, temp, 0, temp_length);
		String temp_string = new String(temp, "euc-kr");
		String[] opinions = temp_string.split("\r\n");
		
		op = new Opinion[opinions.length / 5];
		for(int i = 0; i < opinions.length / 5 ; i++) {
			op[i] = new Opinion();
		}

		for (int i = 0; i < opinions.length / 5; i++) {
			//for (int j = 0; j < 5; j++) {
				op[i].num = opinions[5 * i];
				op[i].nick = opinions[5 * i + 1];
				op[i].opinion = opinions[5 * i + 2];
				op[i].like = opinions[5 * i + 3];
				op[i].unlike = opinions[5 * i + 4];
			//}

		}
	}
	
	public float return_grade() {
		return this.avg_grade;
	}
}
